import { callCloudFun } from "./callCloudFun";
// uni.navigateTo({
// 	url: '/pages/user/user?place=' + params.place
// })

export const wxLogin = () => {
	return new Promise((resolve, reject) => {
		callCloudFun('userLogin').then(res => {
			wx.setStorageSync('userId', res.id)
			resolve(res)
		}).catch(reason => {
			wx.reLaunch({
				url: 'pages/index/index'
			})
			reject(reason)
		})
	})
}

export const urlParse = (path : string) => {
	const urlParams = path.split("?")
	const url = urlParams[0].startsWith('/') ? urlParams[0].slice(1) : urlParams[0]
	let params : Record<string, string> = {}
	if (!urlParams[1]) return { url, params }
	const paramsArr = urlParams[1].split('&')
	paramsArr.forEach(item => {
		const map = item.split('=')
		if (map[1])
			params[map[0]] = map[1]
	})
	return { url, params }
}